class Solution(object):
    def numSubarrayProductLessThanK(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """
        n = len(nums)
        left = 0
        right = 0
        base = 1
        total = 0
        while right < n:
            base *= nums[right]
            if base < k:
                total += (right - left + 1)
            else:
                while base >= k and left <= right:
                    base = base // nums[left]
                    left += 1
                total += (right - left + 1)
            right += 1
        return total


data = Solution()
nums = [10, 5, 2, 6]
k = 100
print(data.numSubarrayProductLessThanK(nums, k))
